﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;


public partial class Admin_StrategicDateModify : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Bind();
        }
    }

    void Bind()
    {
        if (Request.QueryString["Id"] != null)
        {
            string sql = @"SELECT [Id],[StrategicDate],[IsDelete] FROM [DS_StrategicDate] WHERE Id = " + Utility.HttpHelp.getParamsString("Id");
            DataTable dt = DAL.SqlHelper.ExecuteDataset(DAL.SqlHelper.connStr, System.Data.CommandType.Text, sql).Tables[0];
            if (dt.Rows.Count > 0)
            {
                this.txtStrategicDateName.Text = dt.Rows[0]["StrategicDate"].ToString();
            }
        }
        else
        {
            this.btnAdd.Text = "添加";
        }
    }

    protected void btnAdd_Click(object sender, EventArgs e)
    {
        if (Request.QueryString["Id"] != null)
        {
            string sql = "UPDATE DS_StrategicDate SET StrategicDate ='" + this.txtStrategicDateName.Text + "' WHERE [Id] =" + Utility.HttpHelp.getParamsString("Id");
            if (DAL.SqlHelper.ExecuteNonQuery(DAL.SqlHelper.connStr, System.Data.CommandType.Text, sql) > 0)
            {
                Utility.HttpHelp.redirectPage("StrategicPlanDateManager.aspx");
            }
            else
            {
                Utility.Error.RedirectErrorPage("修改战略周期未成功，请重试！");
            }
        }
        else
        {
            string sql = @"INSERT INTO  [DS_StrategicDate]
                                       ([StrategicDate]
                                       ,[IsDelete])
                                 VALUES
                                       ('"+this.txtStrategicDateName.Text+@"'
                                       ,0 )";
            if (DAL.SqlHelper.ExecuteNonQuery(DAL.SqlHelper.connStr, System.Data.CommandType.Text, sql) > 0)
            {
                Utility.HttpHelp.redirectPage("StrategicPlanDateManager.aspx");
            }
            else
            {
                Utility.Error.RedirectErrorPage("添加战略周期未成功，请重试！");
            }
        }
    }
    protected void btnReset_Click(object sender, EventArgs e)
    {
        this.txtStrategicDateName.Text = string.Empty;
    }
}